class Ems::RecordsController < Ems::BaseController
  before_action :set_staff, :set_search_params
  def index
    @records = @staff.send(@type).by_month(@current_month)
  end

  private
  def set_staff
    @staff = StoreStaff.find(params[:store_staff_id])
  end

  def set_search_params
    @type = params[:type] || 'salaries_log'
    @partial = @type
    if params[:month].present?
      date_array = params[:month].split("-").map(&:to_i)
      @current_month = DateTime.new(date_array.first, date_array.last)
    else
      @current_month = Time.now
    end
    @format_month = @current_month.strftime("%Y-%m")
  end
end
